<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class User {
            constructor(name, role, pages) {
                this.name = name
                this.role = role
                this.pages = pages
            }
            welcome() {
                console.log('欢迎回来', this.name)
            }
            dataShow() {
                // abstract
                throw new Error("抽象方法需要被实现")
            }
        }
        class SuperAdmin extends User {
            constructor(name) {
                super(name, "superadmin", ["home", "user-manage", "right-manage", "news-manage"])
            }
            dataShow() {
                // abstract
                console.log('superadmin-datashow')
            }
            addRight() {

            }
            addUser() {

            }
        }

        class Admin extends User {
            constructor(name) {
                super(name, "admin", ["home", "user-manage", "news-manage"])
            }
            dataShow() {
                console.log('admin-datashow')
            }
            addRight() {

            }
            addUser() {

            }
        }

        class Editor extends User {
            constructor(name) {
                super(name, "admin", ["home", "news-manage"])
            }
            dataShow() {
                console.log('editor-datashow')
            }
        }

        function getAbstractUserFactory(role) {
            switch (role) {
                case "superadmin":
                    return SuperAdmin
                case "admin":
                    return Editor
                default:
                    throw new Error("参数错误")
            }
        }
        let userClass = getAbstractUserFactory("admin")
        let user = new userClass("kerwin")
        user.dataShow()
        console.log(userClass)


    </script>
</body>

</html>